package com.sun.alen.mapper;

import com.sun.alen.entity.Admin;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface AdminMapper {

    @Select("select * from admin")
    List<Admin> getAdminAll();

    @Insert("INSERT INTO `admin`(adminId, adminName, adminPassword, adminPhoto, adminPhone) " +
            "VALUES(#{adminId}, #{adminName}, #{adminPassword}, #{adminPhoto}, #{adminPhone})")
    void addAdmin(Admin admin);

    @Select("select * from `admin` where adminName=#{adminName} and adminPassword=#{adminPassword}")
    Admin loginByAdmin(Admin admin);

    @Update("update `admin` set adminPhoto=#{adminPhoto} ,adminPhone =#{adminPhone} where adminId=#{adminId}")
    boolean updateAdminPhoto(Admin admin);

    @Select("select * from `admin` where adminId=#{adminId}")
    Admin selectAdminById(Integer adminId);

    @Update("update `admin` set adminPassword=#{adminPassword} where adminId=#{adminId}")
    boolean updateAdminPassword(Admin admin);

    @Update("update `admin` set adminPassword=#{pass} where adminPhone = #{phone}")
    boolean repassAdmin(String phone, String pass);

    @Select("select count(*) from `admin` where adminPhone = #{phone}")
    int selectAdminCountByPhone(String phone);

    @Select("select count(*) from `admin` where adminName = #{name}")
    int selectAdminCountByName(String name);

    @Select("select * from `admin` where adminName=#{adminName} and adminPassword=#{adminPassword}")
    Admin login(Admin admin);

    @Update("update `admin` set adminPassword=#{pass} where adminPhone = #{phone}")
    boolean repass(String phone, String pass);
}
